import {defineStore} from "pinia";
import {reqHospitalDepartment, reqHospitalDetail} from "@/api/hospital";
import type {DepartmentResponseData, HospitalDetail} from "@/api/hospital/type.ts";
import {DetailState} from "@/store/modules/interface";


//pinia仓库写法:组合式api,选择式api写法
const useDetailStore = defineStore('Detail', {
    state: ():DetailState => {
        return {
            // 医院详情的数据
            hospitalInfo:({} as HospitalDetail),

            //医院接口的数据
            departmentArr: []
        }
    },
    actions: {
        //获取医院详情的方法
        async getHospital(hoscode: string) {
            let result: HospitalDetail = await reqHospitalDetail(hoscode)
            if(result.code == 200){
                // @ts-ignore
                this.hospitalInfo = result.data
            }
        },
        //获取医院详情的方法
        async getDepartment(hoscode: string) {
            let result: DepartmentResponseData = await reqHospitalDepartment(hoscode)
            if(result.code == 200){
                // @ts-ignore
                this.departmentArr = result.data
            }
        }
    },
    getters: {}
})

export default useDetailStore